package com.example.spidertp.core.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.spidertp.core.SpiderThreadPool;
import com.example.spidertp.core.mapper.TpArgumentRecordMapper;
import com.example.spidertp.core.model.entity.TpArgumentRecord;
import com.example.spidertp.core.model.param.SpiderThreadPoolArgsParam;
import com.example.spidertp.core.service.TpArgumentRecordService;
import com.example.spidertp.utils.DateUtils;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author xiong.bo
 * @version 1.0
 * @date 2023/7/22 1:30 下午
 */

@Service
public class TpArgumentRecordServiceImpl extends ServiceImpl<TpArgumentRecordMapper, TpArgumentRecord>
        implements TpArgumentRecordService {


    @Override
    public void createRecord(String poolName, SpiderThreadPool threadPool, SpiderThreadPoolArgsParam argsParam) {
        TpArgumentRecord ar = new TpArgumentRecord();
        ar.setPoolName(poolName);
        ar.setLastCorePoolSize(threadPool.getCorePoolSize());
        ar.setLastMaximumPoolSize(threadPool.getMaximumPoolSize());
        ar.setLastKeepAliveTime(threadPool.getKeepAliveTime(TimeUnit.SECONDS));
        ar.setCurrentCorePoolSize(argsParam.getCorePoolSize());
        ar.setCurrentMaximumPoolSize(argsParam.getMaximumPoolSize());
        ar.setCurrentKeepAliveTime(argsParam.getKeepAliveTime());
        ar.setCreateTime(DateUtils.getCurrentTimestamp());
        ar.setCreateUser("admin");
        this.save(ar);
    }
}
